package com.hx.hospital.mapper;

import com.hx.hospital.pojo.Yuyue;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface YuyueMapper extends Mapper<Yuyue> {

    @Results(id = "YuyueResult",
             value = {@Result(property = "id",column = "id",jdbcType = JdbcType.BIGINT),
                     @Result(property = "doctorId",column = "doctor_id",jdbcType = JdbcType.BIGINT),
                     @Result(property = "doctorName",column = "doctor_name",jdbcType = JdbcType.VARCHAR),
                     @Result(property = "doctorPosition",column = "doctor_position",jdbcType = JdbcType.VARCHAR),
                     @Result(property = "detailDepartmentName",column = "detail_department_name",jdbcType = JdbcType.VARCHAR),
                     @Result(property = "floor",column = "floor",jdbcType = JdbcType.VARCHAR),
                     @Result(property = "doctorDate",column = "doctor_date",jdbcType = JdbcType.DATE),
                     @Result(property = "receptionCapacity",column = "reception_capacity",jdbcType = JdbcType.VARCHAR),
                     @Result(property = "dateState",column = "date_state",jdbcType = JdbcType.BIGINT),
                     @Result(property = "userId",column = "user_id",jdbcType = JdbcType.BIGINT),
                     @Result(property = "userName",column = "user_name",jdbcType = JdbcType.VARCHAR),
                     @Result(property = "yuyueState",column = "yuyue_state",jdbcType = JdbcType.BIGINT),
             })
    @Select("SELECT\n" +
            "y.id,\n" +
            "y.doctor_date,\n" +
            "y.reception_capacity,\n" +
            "y.date_state,\n" +
            "y.yuyue_state,\n" +
            "d.`name` AS doctor_name,\n" +
            "d.doctor_photo,\n" +
            "dp.position AS doctor_position,\n" +
            "dd.detailed_department_name as detailDepartmentName,\n" +
            "f.floor,\n" +
            "u.username,\n" +
            "y.user_id\n" +
            "FROM\n" +
            "yuyue AS y\n" +
            "LEFT JOIN doctor AS d ON y.doctor_id = d.id\n" +
            "LEFT JOIN `user` AS u ON y.user_id = u.id\n" +
            "LEFT JOIN detailed_departments AS dd ON d.detailed_departments_id = dd.id\n" +
            "LEFT JOIN doctor_position AS dp ON d.position_id = dp.id\n" +
            "LEFT JOIN floor AS f ON dd.floor_id = f.id\n" +
            "WHERE\n" +
            "u.id =#{user_id}\n")
    public List<Yuyue> findYuyueAll(Long userId);


    @ResultMap("YuyueResult")
    @Select("SELECT\n" +
            "y.id,\n" +
            "y.doctor_date,\n" +
            "y.reception_capacity,\n" +
            "y.date_state,\n" +
            "y.yuyue_state,\n" +
            "d.`name` AS doctor_name,\n" +
            "d.doctor_photo,\n" +
            "dp.position AS doctor_position,\n" +
            "dd.detailed_department_name as detailDepartmentName,\n" +
            "f.floor,\n" +
            "u.username,\n" +
            "y.user_id\n" +
            "FROM\n" +
            "yuyue AS y\n" +
            "LEFT JOIN doctor AS d ON y.doctor_id = d.id\n" +
            "LEFT JOIN `user` AS u ON y.user_id = u.id\n" +
            "LEFT JOIN detailed_departments AS dd ON d.detailed_departments_id = dd.id\n" +
            "LEFT JOIN doctor_position AS dp ON d.position_id = dp.id\n" +
            "LEFT JOIN floor AS f ON dd.floor_id = f.id\n" +
            "WHERE\n" +
            "y.id = #{id}\n")
    public List<Yuyue> findYuyueById(Long Id);




}
